﻿using System.ServiceModel;
using System.Data.SqlClient;
using System.Data;

namespace BLL.SystemMan
{
    [ServiceContract]
    public class Clientsm
    {
        DAL.DALMethod myDAL = new DAL.DALMethod();
        /// <summary>
        /// （下拉框）客户类型
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectSrType()
        {
            SqlParameter[] sql =
            {
                new SqlParameter ("@type",SqlDbType.VarChar),
            };
            sql[0].Value = "SelectCustomerType";
            DataSet ds = myDAL.QueryDataSet("Clientsm", sql);
            return ds;
        }

        /// <summary>
        /// （下拉框）所属地区
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelDisName()
        {
            SqlParameter[] sql =
            {
                new SqlParameter ("@type",SqlDbType.VarChar),
            };
            sql[0].Value = "SelectDisName";
            DataSet ds = myDAL.QueryDataSet("Clientsm", sql);
            return ds;
        }

        /// <summary>
        /// （下拉框）业务员
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectPmethod()
        {
            SqlParameter[] sql =
            {
                new SqlParameter ("@type",SqlDbType.VarChar),
            };
            sql[0].Value = "SelectEmployeeName";
            DataSet ds = myDAL.QueryDataSet("Clientsm", sql);
            return ds;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet CheckClientsm()
        {
            //声明参数数组对象
            SqlParameter[] sqls =
            {
                //实例化数组对象，查询无条件使用@type，有条件再添加其他的@
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //数组元素赋值
            sqls[0].Value = "SelectClientsm";//存储语句名称
            //调用数据层查询方法
            DataSet ds = myDAL.QueryDataSet("Clientsm", sqls);
            return ds;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="intCustomerTypeID"></param>
        /// <param name="strCustomerName"></param>
        /// <param name="strContactPerson"></param>
        /// <param name="strContactNumber"></param>
        /// <param name="intDisID"></param>
        /// <param name="strContactAddress"></param>
        /// <param name="intEmployeeID"></param>
        /// <param name="strRemark"></param>
        /// <param name="blDefaultNo"></param>
        /// <param name="blDisabledNo"></param>
        /// <returns></returns>
        [OperationContract]
        public int InsertManage(int intCustomerTypeID, string strCustomerName,
        string strContactPerson, string  strContactNumber, int intDisID, string strContactAddress,  
        int intEmployeeID, string strRemark, bool blDefaultNo, bool blDisabledNo)
        {
            //实例化对象数组
            SqlParameter[] sql =
           {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@customerTypeID",SqlDbType.Int),
                new SqlParameter("@customerName",SqlDbType.NVarChar),
                new SqlParameter("@contactPerson",SqlDbType.NVarChar),
                new SqlParameter("@contactNumber",SqlDbType.NVarChar),
                new SqlParameter("@disID",SqlDbType.Int),
                new SqlParameter("@contactAddress",SqlDbType.NVarChar),
                new SqlParameter("@employeeID",SqlDbType.Int),
                new SqlParameter("@remark",SqlDbType.NVarChar),
                new SqlParameter("@defaultNo",SqlDbType.Bit),
                new SqlParameter("@disabledNo",SqlDbType.Bit)
            };
            sql[0].Value = "NewSupplier";
            sql[1].Value = strCustomerName;//名称
            sql[2].Value = strContactPerson;//联系人
            sql[3].Value = strContactNumber;//联系电话
            sql[4].Value = intCustomerTypeID;//供应商类型
            sql[5].Value = strRemark;//备注
            sql[6].Value = intDisID;//所属地区
            sql[7].Value = intEmployeeID;//期初应付
            sql[8].Value = strContactAddress;//联系地址
            sql[9].Value = blDefaultNo;
            sql[10].Value = blDisabledNo;
            //调用数据层新增方法
            int intCount = myDAL.UpdateData("Clientsm", sql);
            //返回受影响行数
            return intCount;
        }

        
        [OperationContract]
        public int UpdateStaff(int intCustomerTypeID, string strCustomerName,
     string strContactPerson, string strContactNumber, int intDisID, string strContactAddress,
     int intEmployeeID, string strRemark, bool blDefaultNo, bool blDisabledNo,int intCustomerID)
        {
            //实例化对象数组
            SqlParameter[] sql =
           {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@customerTypeID",SqlDbType.Int),
                new SqlParameter("@customerName",SqlDbType.NVarChar),
                new SqlParameter("@contactPerson",SqlDbType.NVarChar),
                new SqlParameter("@contactNumber",SqlDbType.NVarChar),
                new SqlParameter("@disID",SqlDbType.Int),
                new SqlParameter("@contactAddress",SqlDbType.NVarChar),
                new SqlParameter("@employeeID",SqlDbType.Int),
                new SqlParameter("@remark",SqlDbType.NVarChar),
                new SqlParameter("@defaultNo",SqlDbType.Bit),
                new SqlParameter("@disabledNo",SqlDbType.Bit),
                new SqlParameter("@customerID",SqlDbType.Int)
            };
            sql[0].Value = "NewSupplier";
            sql[1].Value = strCustomerName;//名称
            sql[2].Value = strContactPerson;//联系人
            sql[3].Value = strContactNumber;//联系电话
            sql[4].Value = intCustomerTypeID;//供应商类型
            sql[5].Value = strRemark;//备注
            sql[6].Value = intDisID;//所属地区
            sql[7].Value = intEmployeeID;//期初应付
            sql[8].Value = strContactAddress;//联系地址
            sql[9].Value = blDefaultNo;
            sql[10].Value = blDisabledNo;
            sql[11].Value = intCustomerID;
            //调用数据层新增方法
            int intCount = myDAL.UpdateData("Clientsm", sql);
            //返回受影响行数
            return intCount;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="intCustomerID"></param>
        /// <returns></returns>
        [OperationContract]
        public int DelectStaff(int intCustomerID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@CustomerID",SqlDbType.Int),
                                                  };
            SQLCMDpas[0].Value = "DeleteCustomer";
            SQLCMDpas[1].Value = intCustomerID;
            int count = myDAL.UpdateData("Clientsm", SQLCMDpas);
            return count;
        }

        /// <summary>
        /// 默认客户
        /// </summary>
        /// <param name="defaultNo"></param>
        /// <param name="intCustomerID"></param>
        /// <returns></returns>
        [OperationContract]
        public int UpdateLine(bool bldefaultNo, int intCustomerID)
        {
            SqlParameter[] sql ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@defaultNo",SqlDbType.Bit),
                                          new  SqlParameter ("@CustomerID",SqlDbType.Int),
                                              };
            sql[0].Value = "AcquiesceIn";
            sql[1].Value = bldefaultNo;
            sql[2].Value = intCustomerID;
            int count = myDAL.UpdateData("Clientsm", sql);
            return count;
        }

        /// <summary>
        /// 禁用
        /// </summary>
        /// <param name="defaultNo"></param>
        /// <param name="intCustomerID"></param>
        /// <returns></returns>
        [OperationContract]
        public int DisaNo(bool bldisabledNo, int intCustomerID)
        {
            SqlParameter[] sql ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@disabledNo",SqlDbType.Bit),
                                          new  SqlParameter ("@CustomerID",SqlDbType.Int),
                                              };
            sql[0].Value = "StopOrNotLine";
            sql[1].Value = bldisabledNo;
            sql[2].Value = intCustomerID;
            int count = myDAL.UpdateData("Clientsm", sql);
            return count;
        }
    }
}
